package com.lattice.exception;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * @author mis_wu
 * @date 2022/6/21 20:52
 * @todo 业务异常
 */
public class BusinessException extends RuntimeException {

    public BusinessException() {
        super();
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    protected BusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

    public static BusinessException build(String ...msg){
        StringBuilder tip = new StringBuilder("系统异常,请联系管理员!!!");
        //String tip = "系统异常,请联系管理员!!!";
        if (ObjectUtils.isNotEmpty(msg)){
            for (Object o : Arrays.stream(msg).toArray()) {
                tip.append(",").append(o);
            }
            //tip = StringUtils.join(Arrays.stream(msg).toArray(), ",");
        }
        return new BusinessException(tip.toString());
    }

}
